package org.example.leetCode;

/**
 * @author Vader
 * @date 2021/11/4
 **/
public class IsPerfectSquare {
    public static void main(String[] args) {
        int num =14;
        System.out.println(isPerfectSquare(num));
    }

    public static boolean isPerfectSquare(int num) {
        if (num == 0 || num == 1) {
            return true;
        }

        int left = 1;
        int right = num;

        while (left <= right) {
            int mid = left + (right - left) / 2;
            int temp = num / mid;
            int reminder = num % mid;
            if (temp == mid&&reminder==0) {
                return true;
            } else if (temp > mid) {
                left = mid+1;
            } else {
                right = mid-1;
            }
        }
        return false;
    }
}
